<template>
    <div class="gxgxToplbt">
        <div style="width: 18%;">
            <classification title="供需分类" :sysProductTypeData="sysProductTypeData" @list-click="gxListJump" />
        </div>
        <div style="width: calc(64% - 40px);">
            <RoundCornerCarousel :lbtImg="lbtImg.slice(0, 5)" />
        </div>
        <div class="gxglRightImg">
            <div class="gxglRightImgdw" style="margin-bottom: 20px;">
                <img style="width: 100%;height: 100%;" :src="lbtImg[0]?.url" alt="">
                <div class="gxglRightImgText">{{ lbtImg[0]?.name }}</div>
            </div>
            <div class="gxglRightImgdw">
                <img style="width: 100%;height: 100%;" :src="lbtImg[1]?.url" alt="">
                <div class="gxglRightImgText">{{ lbtImg[0]?.name }}</div>
            </div>
        </div>
    </div>
    <div style="margin-top: 25px;">
        <HorizontalScrolling title="精选供需" :products="productList" />
    </div>
    <TabCard title="产业直供" text="产业源头 好货直供" v-model="cyzgTabsValue" :TabsList="sysRegionData">
        <template #nr>
            <div class="cyzgnrBox">
                <div class="cyzgnrBox_left">
                    <div class="cyzgnrBox_leftTitle">
                        {{sysRegionData.find(item => item.dictValue === cyzgTabsValue)?.dictLabel || '默认标题'}}
                    </div>
                    <div class="cyzgnrLeftList">
                        <div class="cyzgnrLeftcjmc" v-for="item in cpzgData" :key="item">{{ item.enterprise_name }}
                        </div>
                    </div>
                </div>
                <div class="cyzgnrBox_right">
                    <div style="width: calc(20% - 16px);" v-for="item in cpzgData" :key="item.id">
                        <goodsBox :filePathType="false" :applyPadding="false" :formData="item" />
                    </div>
                </div>
            </div>
        </template>
    </TabCard>
    <TabCard title="供需厂商" text="产业源头 好货直供" v-model="gxcsTabsValue" :TabsList="sysProductTypeData">
        <template #nr>
            <div class="gxcsBox">
                <div class="gxcsFor" v-for="(item, index) in lcSupplyDemandInfosloadGongXuInChangShangFoNodata"
                    :key="index">
                    <div class="gxcsForTop">
                        <img class="gxcsForTopImg"
                            :src="item.enterprise_file_path == 'UpLoadFiles\\qiye.png' ? `https://image.pollinations.ai/prompt/公司大厦${item.enterprise_id}` : store.imgfengMian + item.enterprise_file_path"
                            alt="" loading="lazy">
                        <div class="gxcsForTopText">{{ item.enterprise_name }}</div>
                        <div class="gxcsForTopljcs" @click="gxcsljcsfun(item.enterprise_id)">了解厂商</div>
                    </div>
                    <div class="gxcsForButton">
                        <div class="gxcsButtonBox" v-for="(ite, inde) in item.products" :key="inde">
                            <img class="gxcsButtonImg"
                                :src="ite.file_path == 'UpLoadFiles\\shop.png' ? `https://image.pollinations.ai/prompt/${ite.product_name.split('、')[0]}` : store.imgfengMian + ite.file_path"
                                alt="" loading="lazy">
                            <div class="gxcsButtonText">{{ ite.product_name }}</div>
                        </div>
                    </div>
                </div>
            </div>
        </template>
    </TabCard>
    <div class="gxgxCardBox">
        <div class="gxgxCardBoxTop">
            <div class="gxgxCardTopTitle">为你推荐</div>
            <div class="gxgxCardTopText">产业源头 好货直供</div>
        </div>
        <div class="gxgxCardList">
            <div style="width: calc(20% - 16px);" v-for="item in gxtjData" :key="item">
                <goodsBox :filePathType="false" :applyPadding="false" :formData="item" />
            </div>
        </div>
    </div>
</template>
<script setup>
import classification from '@/components/general/classification.vue';
import RoundCornerCarousel from '@/components/general/RoundCornerCarousel.vue';
import HorizontalScrolling from '@/components/general/HorizontalScrolling.vue';
import TabCard from '@/components/general/TabCard.vue';
import goodsBox from '@/components/general/goodsBox.vue';
import { sysProductType, sysRegion } from '@/api/dictionary.js';
import { lcSupplyDemandInfosLoadGongXuInFoNo, lcSupplyDemandInfosloadGongXuInChangShangFoNo } from '@/api/api.js';
import { ref, onMounted } from "vue";
import { useStore } from '@/store/store';
const store = useStore()
import { useRouter } from 'vue-router';
const router = useRouter();
const lbtImg = ref([]);
const productList = ref([])
const gxtjData = ref([]) // 推荐供需
// 精选，产业直供，推荐
const lcSupplyDemandInfosLoadGongXuInFoNofun = async (obj) => {
    const parameter = {
        pageNum: 1,
        pageSize: 10,
        ...obj
    }
    const res = await lcSupplyDemandInfosLoadGongXuInFoNo(parameter);
    if (obj.is_jingxuan) {
        productList.value = res.data
        lbtImg.value = res.data.map(item => ({
            name: item.product_name,
            url: item.file_path == 'UpLoadFiles\\shop.png' ? `https://image.pollinations.ai/prompt/${item.product_name.split('、')[0]}` : store.imgfengMian + item.file_path
        }))
        return
    }
    if (obj.region_id) {
        cpzgData.value = res.data
        return
    }
    gxtjData.value = res.data
}

// 商品类型
const gxcsTabsValue = ref('10001')
const sysProductTypeData = ref([]);
const sysProductTypefun = async () => {
    const res = await sysProductType();
    sysProductTypeData.value = res.data;
    gxcsTabsValue.value = res.data[0].dictValue
    lcSupplyDemandInfosloadGongXuInChangShangFoNoFun()
}
const lcSupplyDemandInfosloadGongXuInChangShangFoNodata = ref([])
const lcSupplyDemandInfosloadGongXuInChangShangFoNoFun = async () => {
    const res = await lcSupplyDemandInfosloadGongXuInChangShangFoNo({ page: 1, limit: 3, val: gxcsTabsValue.value })
    lcSupplyDemandInfosloadGongXuInChangShangFoNodata.value = res.data
}
// 县区字典数据
const cpzgData = ref([]);
const cyzgTabsValue = ref('371302')
const sysRegionData = ref([]);
const sysRegionfun = async () => {
    const res = await sysRegion()
    sysRegionData.value = res.data
    cyzgTabsValue.value = res.data[0].dictValue
    lcSupplyDemandInfosLoadGongXuInFoNofun({ region_id: cyzgTabsValue.value }) // 产业直供
}
onMounted(() => {
    sysProductTypefun() // 商品类型获取
    sysRegionfun() // 县区字典获取
    lcSupplyDemandInfosLoadGongXuInFoNofun({ is_jingxuan: 1 }) // 精选
    lcSupplyDemandInfosLoadGongXuInFoNofun({}) // 推荐
})
// 列表点击
const gxListJump = (val) => {
    router.push({
        path: '/supplyList',
        query: { type: val.dictValue }
    });
}
// 厂商详情点击
const gxcsljcsfun = (id) => {
    router.push({
        path: '/EnterpriseDetail',
        query: { id: id }
    });
}
</script>
<style scoped lang="scss">
.gxgxToplbt {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.gxglRightImg {
    width: 18%;
    background: #fff;
}

.gxglRightImgdw {
    width: 100%;
    height: 180px;
    position: relative;
    border-radius: 8px;
    overflow: hidden;

    .gxglRightImgText {
        position: absolute;
        bottom: 0;
        padding: 8px 20px;
        width: 100%;
        background: rgba(0, 0, 0, 0.5);
        font-size: 14px;
        color: #FFFFFF;
    }
}

.cyzgnrBox {
    display: flex;
    gap: 10px;

    .cyzgnrBox_left {
        width: 18%;
        // height: 500px;
        background: linear-gradient(180deg, #7BC787 0%, #279839 100%);
        flex-shrink: 0;
        padding: 12px 10px;

        .cyzgnrBox_leftTitle {
            font-weight: bold;
            font-size: 26px;
            color: #FFFFFF;
            padding: 8px 0;
            border-bottom: 3px solid #FFFFFF;
        }

        .cyzgnrLeftList {
            margin-top: 30px;

            .cyzgnrLeftcjmc {
                font-size: 12px;
                padding: 6px;
                color: #FFFFFF;
                border-radius: 18px;
                border: 2px solid #FFFFFF;
                margin-bottom: 10px;
            }
        }
    }

    .cyzgnrBox_right {
        flex-grow: 1;
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 20px;
    }
}

.gxcsBox {
    display: flex;
    align-items: center;
    gap: 20px;
    margin: 5px 0;

    .gxcsFor {
        width: calc(33.33% - 13.33px);
        flex-shrink: 0;
        background: #FFFFFF;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1),
            0 8px 16px rgba(0, 0, 0, 0.1); // 添加双层阴影增强立体感
        border-radius: 8px;
        padding: 0 26px;

        .gxcsForTop {
            display: flex;
            align-items: center;
            padding: 26px 0;
            border-bottom: 1px solid #EEEEEE;

            .gxcsForTopImg {
                width: 46px;
                height: 46px;
                border-radius: 50%;
                flex-shrink: 0;
            }

            .gxcsForTopText {
                font-size: 14px;
                color: #1F1F1F;
                margin-left: 20px;
                flex-grow: 1;
            }

            .gxcsForTopljcs {
                padding: 6px 10px;
                border: 1px solid #CCCCCC;
                border-radius: 4px;
                font-weight: 300;
                font-size: 12px;
                color: #333333;
                flex-shrink: 0;
                cursor: pointer;
            }
        }

        .gxcsForButton {
            display: flex;
            align-items: center;
            margin-top: 10px;
            margin-bottom: 20px;
            gap: 10px;

            .gxcsButtonBox {
                width: 50%;
                display: flex;
                flex-direction: column;
                align-items: center;

                .gxcsButtonImg {
                    width: 100%;
                    height: auto;
                    aspect-ratio: 1/1; // 宽高比1:1（可按需修改比例）
                    object-fit: cover; // 保持比例填充容器
                    margin-bottom: 10px;
                }

                .gxcsButtonText {
                    font-size: 14px;
                    color: #1F1F1F;
                    overflow: hidden;
                    white-space: nowrap;
                    text-overflow: ellipsis;
                    max-width: 100%;
                }
            }
        }
    }
}

.gxgxCardBox {
    margin-top: 20px;
    width: 100%;
    height: 100%;
    background: linear-gradient(180deg, #F4F9FF 0%, #FFFFFF 19%), #FFFFFF;
    box-shadow: 0px 0px 2px 0px rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    padding: 20px;

    .gxgxCardBoxTop {
        display: flex;
        align-items: flex-end; // 底部对齐
        margin-bottom: 15px; // 增加下边距

        .gxgxCardTopTitle {
            font-weight: bold;
            font-size: 30px;
            color: #1F1F1F;
            line-height: 1;
        }

        .gxgxCardTopText {
            margin-left: 15px;
            font-size: 12px;
            color: #7D7D7D;
        }
    }

    .gxgxCardList {
        display: flex;
        flex-wrap: wrap;
        gap: 20px;
    }
}
</style>